//
//  MainTabBar.swift
//  01_新浪微博
//
//  Created by 黄蓉 on 15/12/12.
//  Copyright © 2015年 黄蓉. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        //设置
        let w = bounds.width/5
        let h = bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        //设置items的frame
        var index: CGFloat = 0
        for subView in subviews {
            //判断tabbar子控件的类型,也不能为Button,如果不判断,就会多创建一个button
            if subView is UIControl && !(subView is UIButton){
//                print(subView)
                subView.frame = CGRectOffset(rect, w * index, 0)
                //在第二个item后面添加一个item,
                index += (index == 1 ? 2:1)
            }
        }

        composeButton.frame = CGRectOffset(rect, w * 2, 0)
        addSubview(composeButton)
    }
    lazy var composeButton: UIButton = UIButton(normalImageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")
}

